package com.prd.controller;


import com.prd.dto.AttendanceOutsideDTO;
import com.prd.dto.AttendanceVocationDTO;
import com.prd.service.AttendanceVocationService;
import com.prd.util.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lizhaoyi
 * @since 2023-10-18
 */
@Api(tags={"假期管理"})
@RestController
@RequestMapping("/api/attendanceVocation")
public class AttendanceVocationController {

    @Autowired
    private AttendanceVocationService attendanceVocationService;

    /**
     * 申请假期并启动工作流
     * @param attendanceVocationDTO
     * @return
     */
    @ApiOperation("申请假期并启动工作流")
    @PostMapping("/askForVocation")
    public JsonData askForVocation(@RequestBody AttendanceVocationDTO attendanceVocationDTO){

        JsonData jsonData = attendanceVocationService.askForVocation(attendanceVocationDTO);

        return jsonData;
    }

    @ApiOperation("分页查询假期记录")
    @GetMapping("page")
    public JsonData pageVocationList(
            @ApiParam(value = "当前页")  @RequestParam(value = "page", defaultValue = "1") int page,
            @ApiParam(value = "每页显示多少条") @RequestParam(value = "size", defaultValue = "10") int size,
            @ApiParam(value = "用户id") @RequestParam(value = "userId") String userId
    ){

        Map<String,Object> pageResult = attendanceVocationService.page(page,size,userId);

        return JsonData.buildSuccess(pageResult);


    }

    /**
     * 销假操作
     * @param attendanceVocationDTO
     * @return
     */
    @ApiOperation("销假操作")
    @PostMapping("/cancelVocation")
    public JsonData cancelVocation(@RequestBody AttendanceVocationDTO attendanceVocationDTO){

        JsonData jsonData = attendanceVocationService.cancelVocation(attendanceVocationDTO);

        return jsonData;
    }

    @ApiOperation("查看假期申请详情")
    @GetMapping("detail")
    public JsonData detail(
            @ApiParam(value = "假期id") @RequestParam(value = "id") int id,
            @ApiParam(value = "用户id") @RequestParam(value = "userId") String userId
    ){

        JsonData jsonData = attendanceVocationService.getDetail(id,userId);

        return jsonData;

    }

    @ApiOperation("查看工作流程图")
    @GetMapping("showProcessPic")
    public JsonData showProcessPic(HttpServletResponse resp, String processId) throws IOException {

        attendanceVocationService.showProcessPic(resp,processId);

        return JsonData.buildSuccess();
    }

}

